package com.springboot.jwt.config;

import com.springboot.jwt.interceptor.JwtInterceptors;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    private final List<String> excludeList = new ArrayList<>();

    public InterceptorConfig() {
        excludeList.add("/user/test");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        ArrayList<String> pathList = new ArrayList<>();
        pathList.add("/user/**");   // 拦截/user路径下的所有接口

        registry.addInterceptor(new JwtInterceptors())
                .addPathPatterns(pathList)  // 其他接口token验证
                .excludePathPatterns("/user/login")
                .excludePathPatterns(excludeList);    // 所有用户都可以访问
    }
}
